
$(function () {
    $('#accountTb').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        pagination: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/train/record/AccountTable.shtml',
        queryParams: {
            sort: 'addTime',
            order: 'desc'
        },
        columns: [[
            {
                field: 'id',hidden:true
            },
            {field: 'rName', title: '教育名称', width: 150},
            {field: 'hostDeptNamea', title: '主办单位', width: 100, formatter: function (value, row, index) {
                return row.isExternal == '0' ? row.hostDeptIdName : row.hostDeptName;
            }},
            {field: 'trainContent', title: '教育内容', width: 200},
            {field: 'dx', title: '教育对象类别', width: 100,formatter: function (value, row, index) {
                return row.trainTypeIdName+'-'+row.proTypeIdName;
            }},
            {field: 'actualStartTime', title: '教育时间', width: 100},
            {field: 'actualTrainPlace', title: '教育地点', width: 130},
            {field: 'trainTeacher', title: '授课人', width: 100},
            {field: 'actualTrainHour', title: '学时', width: 100},
            {field: 'cj', title: '成绩(人)', width: 100,formatter: function (value, row, index) {
                return '合格：'+ row.realHgUserNum+'；'+'不合格：'+row.realNhUserNum;
            }}
        ]]
    });

    $('#btn_advanced_search').on("click", function () {
        $('#queryForm2').toggle();
        $('#accountTb').datagrid('resize');
    });
    $('#btn_clear').on("click", function () {
        $('#queryForm1').form('reset');
        $('#queryForm2').form('reset');
    });
    var TRAINFORM=CONSTANT.DictionaryTypeDefConstants.TRAINFORM;//培训形式
    queryComboData(TRAINFORM,'trainFormId');
    var TRAIN_TRAINTYPE=CONSTANT.DictionaryTypeDefConstants.TRAIN_TRAINTYPE;//培训类别标识
    queryComboData(TRAIN_TRAINTYPE,'trainTypeId');
    var TRAIN_PROTYPE=CONSTANT.DictionaryTypeDefConstants.TRAIN_PROTYPE;//专业类别标识
    queryComboData(TRAIN_PROTYPE,'professionalTypeId');
    var TRAIN_LEVEL=CONSTANT.DictionaryTypeDefConstants.TRAIN_LEVEL;//培训级别标识
    queryComboData(TRAIN_LEVEL,'trainLevelId');
    queryYearthList("yearAnnual");
});

function queryComboData(code,queryId) {
    var EMPTY_OPTION = {
        id: '',
        text: '请选择'
    };
    var pageId='#'+queryId;
    $.ajax({
        type: 'post',
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',
        data: {code: code},
        dataType: "json",
        success: function (result) {
            $(pageId).combobox({
                loadFilter: function (data) {
                    data.unshift(EMPTY_OPTION);
                    return data;
                },
                data: result,
                valueField: 'id',
                textField: 'text',
                editable: false,
                panelHeight: '200',
                onSelect: function (record) {
                }
            });
        }
    });
}
/**
 * 重新加载表格
 */
function reLoadData() {
    $('#accountTb').datagrid('clearSelections');
    var queryParams1 = $('#queryForm1').serializeJson();
    var queryParams2 = $('#queryForm2').serializeJson();
    var queryParams = $.extend(queryParams1,queryParams2);
    queryParams["sort"] = 'addTime';
    queryParams["order"] = 'desc';
    $('#accountTb').datagrid('options').queryParams = queryParams;
    $("#accountTb").datagrid('reload', ROOT_PATH + '/train/record/AccountTable.shtml');
}
function queryYearthList(id){
    var date = new Date();
    var year = date.getFullYear();
    var yearthData = new Array();
    yearthData.push({id:"",text:"请选择"});
    for(var i =0;i<6;i++){
        var y = {id:year-i,text:(year-i)+'年'}
        yearthData.push(y);
    }
    $('#'+id).combobox(
        {
            data:yearthData,
            valueField:'id',
            textField:'text'
        }
    );
}



